﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XmlDSigEx
{
    public class DigestFactory
    {
        private static List<IDigestProvider> _Providers = new List<IDigestProvider>();

        static DigestFactory()
        {
            // Default configuration.
            AddProvider(new DigestProvider());
        }

        public static void AddProvider(IDigestProvider Provider)
        {
            _Providers.Insert(0, Provider);
        }

        public static IDigestAlgorithm GetDigestAlgorithm(string algorithm)
        {
            foreach (IDigestProvider Provider in _Providers)
            {
                if (Provider.CanHandle(algorithm))
                    return Provider.GetDigest(algorithm);
            }
            throw new UnknownAlgorithmException("No Provider was registered for the canonicalisation algorithm.");
        }
    }
}
